<?php

/**
 * Application Models
 *
 * @package Application_Model
 * @subpackage Model
 * @author <YOUR NAME HERE>
 * @copyright ZF model generator
 * @license http://framework.zend.com/license/new-bsd     New BSD License
 */

/**
 * Abstract class for models
 */
require_once 'ModelAbstract.php';

/**
 * 
 *
 * @package Application_Model
 * @subpackage Model
 * @author <YOUR NAME HERE>
 */
class Application_Model_Questionnaire extends Application_Model_ModelAbstract
{

    /**
     * Database var type int(3)
     *
     * @var int
     */
    protected $_IdQestio;

    /**
     * Database var type int(3)
     *
     * @var int
     */
    protected $_NbrQestio;

    /**
     * Database var type varchar(20)
     *
     * @var string
     */
    protected $_TypeQestio;

    /**
     * Database var type int(50)
     *
     * @var int
     */
    protected $_FormationIdFor;


    /**
     * Parent relation fk_questionnaire_formation1
     *
     * @var Application_Model_Formation
     */
    protected $_Formation;


    /**
     * Dependent relation fk_evalformation_questionnaire1
     * Type: One-to-Many relationship
     *
     * @var Application_Model_Evalformation
     */
    protected $_Evalformation;

    /**
     * Dependent relation fk_evalsession_questionnaire1
     * Type: One-to-Many relationship
     *
     * @var Application_Model_Evalsession
     */
    protected $_Evalsession;

    /**
     * Dependent relation fk_question_questionnaire1
     * Type: One-to-Many relationship
     *
     * @var Application_Model_Question
     */
    protected $_Question;

    /**
     * Sets up column and relationship lists
     */
    public function __construct()
    {
        parent::init();
        $this->setColumnsList(array(
            'id_qestio'=>'IdQestio',
            'nbr_qestio'=>'NbrQestio',
            'type_qestio'=>'TypeQestio',
            'formation_id_for'=>'FormationIdFor',
        ));

        $this->setParentList(array(
            'FkQuestionnaireFormation1'=> array(
                    'property' => 'Formation',
                    'table_name' => 'Formation',
                ),
        ));

        $this->setDependentList(array(
            'FkEvalformationQuestionnaire1' => array(
                    'property' => 'Evalformation',
                    'table_name' => 'Evalformation',
                ),
            'FkEvalsessionQuestionnaire1' => array(
                    'property' => 'Evalsession',
                    'table_name' => 'Evalsession',
                ),
            'FkQuestionQuestionnaire1' => array(
                    'property' => 'Question',
                    'table_name' => 'Question',
                ),
        ));
    }

    /**
     * Sets column id_qestio
     *
     * @param int $data
     * @return Application_Model_Questionnaire
     */
    public function setIdQestio($data)
    {
        $this->_IdQestio = $data;
        return $this;
    }

    /**
     * Gets column id_qestio
     *
     * @return int
     */
    public function getIdQestio()
    {
        return $this->_IdQestio;
    }

    /**
     * Sets column nbr_qestio
     *
     * @param int $data
     * @return Application_Model_Questionnaire
     */
    public function setNbrQestio($data)
    {
        $this->_NbrQestio = $data;
        return $this;
    }

    /**
     * Gets column nbr_qestio
     *
     * @return int
     */
    public function getNbrQestio()
    {
        return $this->_NbrQestio;
    }

    /**
     * Sets column type_qestio
     *
     * @param string $data
     * @return Application_Model_Questionnaire
     */
    public function setTypeQestio($data)
    {
        $this->_TypeQestio = $data;
        return $this;
    }

    /**
     * Gets column type_qestio
     *
     * @return string
     */
    public function getTypeQestio()
    {
        return $this->_TypeQestio;
    }

    /**
     * Sets column formation_id_for
     *
     * @param int $data
     * @return Application_Model_Questionnaire
     */
    public function setFormationIdFor($data)
    {
        $this->_FormationIdFor = $data;
        return $this;
    }

    /**
     * Gets column formation_id_for
     *
     * @return int
     */
    public function getFormationIdFor()
    {
        return $this->_FormationIdFor;
    }

    /**
     * Sets parent relation FormationIdFor
     *
     * @param Application_Model_Formation $data
     * @return Application_Model_Questionnaire
     */
    public function setFormation(Application_Model_Formation $data)
    {
        $this->_Formation = $data;

        $primary_key = $data->getPrimaryKey();
        if (is_array($primary_key)) {
            $primary_key = $primary_key['id_for'];
        }

        $this->setFormationIdFor($primary_key);

        return $this;
    }

    /**
     * Gets parent FormationIdFor
     *
     * @param boolean $load Load the object if it is not already
     * @return Application_Model_Formation
     */
    public function getFormation($load = true)
    {
        if ($this->_Formation === null && $load) {
            $this->getMapper()->loadRelated('FkQuestionnaireFormation1', $this);
        }

        return $this->_Formation;
    }

    /**
     * Sets dependent relations fk_evalformation_questionnaire1
     *
     * @param array $data An array of Application_Model_Evalformation
     * @return Application_Model_Questionnaire
     */
    public function setEvalformation(array $data)
    {
        $this->_Evalformation = array();

        foreach ($data as $object) {
            $this->addEvalformation($object);
        }

        return $this;
    }

    /**
     * Sets dependent relations fk_evalformation_questionnaire1
     *
     * @param Application_Model_Evalformation $data
     * @return Application_Model_Questionnaire
     */
    public function addEvalformation(Application_Model_Evalformation $data)
    {
        $this->_Evalformation[] = $data;
        return $this;
    }

    /**
     * Gets dependent fk_evalformation_questionnaire1
     *
     * @param boolean $load Load the object if it is not already
     * @return array The array of Application_Model_Evalformation
     */
    public function getEvalformation($load = true)
    {
        if ($this->_Evalformation === null && $load) {
            $this->getMapper()->loadRelated('FkEvalformationQuestionnaire1', $this);
        }

        return $this->_Evalformation;
    }

    /**
     * Sets dependent relations fk_evalsession_questionnaire1
     *
     * @param array $data An array of Application_Model_Evalsession
     * @return Application_Model_Questionnaire
     */
    public function setEvalsession(array $data)
    {
        $this->_Evalsession = array();

        foreach ($data as $object) {
            $this->addEvalsession($object);
        }

        return $this;
    }

    /**
     * Sets dependent relations fk_evalsession_questionnaire1
     *
     * @param Application_Model_Evalsession $data
     * @return Application_Model_Questionnaire
     */
    public function addEvalsession(Application_Model_Evalsession $data)
    {
        $this->_Evalsession[] = $data;
        return $this;
    }

    /**
     * Gets dependent fk_evalsession_questionnaire1
     *
     * @param boolean $load Load the object if it is not already
     * @return array The array of Application_Model_Evalsession
     */
    public function getEvalsession($load = true)
    {
        if ($this->_Evalsession === null && $load) {
            $this->getMapper()->loadRelated('FkEvalsessionQuestionnaire1', $this);
        }

        return $this->_Evalsession;
    }

    /**
     * Sets dependent relations fk_question_questionnaire1
     *
     * @param array $data An array of Application_Model_Question
     * @return Application_Model_Questionnaire
     */
    public function setQuestion(array $data)
    {
        $this->_Question = array();

        foreach ($data as $object) {
            $this->addQuestion($object);
        }

        return $this;
    }

    /**
     * Sets dependent relations fk_question_questionnaire1
     *
     * @param Application_Model_Question $data
     * @return Application_Model_Questionnaire
     */
    public function addQuestion(Application_Model_Question $data)
    {
        $this->_Question[] = $data;
        return $this;
    }

    /**
     * Gets dependent fk_question_questionnaire1
     *
     * @param boolean $load Load the object if it is not already
     * @return array The array of Application_Model_Question
     */
    public function getQuestion($load = true)
    {
        if ($this->_Question === null && $load) {
            $this->getMapper()->loadRelated('FkQuestionQuestionnaire1', $this);
        }

        return $this->_Question;
    }

    /**
     * Returns the mapper class for this model
     *
     * @return Application_Model_Mapper_Questionnaire
     */
    public function getMapper()
    {
        if ($this->_mapper === null) {
            $this->setMapper(new Application_Model_Mapper_Questionnaire());
        }

        return $this->_mapper;
    }

    /**
     * Deletes current row by deleting the row that matches the primary key
     *
	 * @see Application_Model_Mapper_Questionnaire::delete
     * @return int|boolean Number of rows deleted or boolean if doing soft delete
     */
    public function deleteRowByPrimaryKey()
    {
        if ($this->getIdQestio() === null) {
            throw new Exception('Primary Key does not contain a value');
        }

        return $this->getMapper()
                    ->getDbTable()
                    ->delete('id_qestio = ' .
                             $this->getMapper()
                                  ->getDbTable()
                                  ->getAdapter()
                                  ->quote($this->getIdQestio()));
    }
}
